#include "diskmap.h"
#include "sniffer.h"
#include <QIcon>
#include <QRegExp>


YDDiskMap::YDDiskMap(QObject* parent) :
    QObject(parent) {
     iconBaidu = new QIcon(":/image/images/baidu.ico");
     regWebBaidu = new QRegExp("(?:http:\\/\\/)?pan\\.baidu\\.com\\/share\\/link\\?shareid=\\d+&uk=\\d+\\/?", Qt::CaseInsensitive);
     regRealBaidu = new QRegExp("<a[\\S\\s]+href=\"(\\S+)\"\\s+id=\"downFileButtom\">", Qt::CaseInsensitive);

     regRealBaidu->setMinimal(true);
}

YDDiskMap::~YDDiskMap() {
    delete iconBaidu;
    delete regWebBaidu;
    delete regRealBaidu;
}

QString YDDiskMap::getText(const QString& type) {
    if (type == "baidu") {
        return "百度";
    } else {
        return "";
    }
}

QIcon* YDDiskMap::getIcon(const QString& type) {
    if (type == "baidu") {
        return iconBaidu;
    } else {
        return nullptr;
    }
}

YDSniffer* YDDiskMap::getSniffer(const QString& type, QObject* parent) {
    if (type == "baidu") {
        return new YDBaiduDiskSniffer(parent);
    } else {
        return nullptr;
    }
}

QRegExp* YDDiskMap::getWebUrlReg(const QString& type) {
    if (type == "baidu") {
        return regWebBaidu;
    } else {
        return nullptr;
    }
}

QRegExp* YDDiskMap::getRealUrlReg(const QString& type) {
    if (type == "baidu") {
        return regRealBaidu;
    } else {
        return nullptr;
    }
}

std::map<QString, QRegExp*> YDDiskMap::getWebUrlRegMap() {
    std::map<QString, QRegExp*>ret;

    ret["baidu"] = regWebBaidu;

    return std::move(ret);
}
